/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package org.ipti.br.tag.entity;

import javax.persistence.Entity;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import org.ipti.br.tag.util.EncryptionUtil;

/**
 *
 * @author ipti
 */
@Entity
public class QuestionsPerson extends AbstractEntity{
    @ManyToOne
    @JoinColumn(name="person_id")
    private Person person;
    
    @ManyToOne
    @JoinColumn(name="questions_id")
    private Questions questions;

    public QuestionsPerson() {
    }

    @Override
    public void generateHash(){
        if(getId() == null){
            String hash = ""
                    + ((this.getPerson() != null) ? this.getPerson().getId() : null)
                    + ((this.getQuestions() != null) ? this.getQuestions().getId() : null);
            this.setId(Long.valueOf(EncryptionUtil.encrypt(hash).hashCode()));
        }
    }
    
    public QuestionsPerson(Person person, Questions questions) {
        this.person = person;
        this.questions = questions;
    }    

    public Person getPerson() {
        return person;
    }

    public void setPerson(Person person) {
        this.person = person;
    }

    public Questions getQuestions() {
        return questions;
    }

    public void setQuestions(Questions questions) {
        this.questions = questions;
    }
}